<template>
  <div>
     <h2>会员登录</h2>
     <hr>
     <table class="table table-bordered">
      <tr>
        <td>会员名称:</td>
        <td>
        <input type="text" v-model="state.Name">
        </td>
      </tr>
      <tr>
        <td>密码:</td>
        <td>
        <input type="text" v-model="state.Pwd">
        </td>
      </tr>
      <tr>
        <td>
          <input type="button" value="登录" @click="login">
        </td>
        <td>
          <input type="button" value="注册" >
        </td>
      </tr>
     </table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router1=useRouter()

var data=reactive({
  state:{
    Name:'',
    Pwd:''
  }
})

var {state}=toRefs(data)
const login = ()=>{
var obj={
  Name:state.value.Name,
  Pwd:state.value.Pwd
}

axios({
  url:'https://localhost:7000/api/Member/Login',
  method:'get',
  params:obj
})
.then(res=>{
   if(res.data.data.id==-1)
   {
    alert('用户名不存在')
    return
   }
   if(res.data.data.id==-2)
   {
    alert('密码错误')
    return 
   }
   if(res.data.data.id>0)
   {
    alert('登陆成功')
    router1.push("/MemberShow")
   }
   
})
.catch(err=>{
  console.log(err);
  alert('登陆失败')
})
}
</script>

<style scoped>

</style>